package proxy.dynamicProxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyTwo {

    private Person person;

    public ProxyTwo(){}

    public ProxyTwo(Person person){
        this.person = person;
    }

    public void run(){
        Person man = (Person) Proxy.newProxyInstance(this.getClass().getClassLoader(),
                person.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("two登场");
                        Object result = method.invoke(person,args);
                        System.out.println("two下线");
                        return result;
                    }
                });
        man.happy();

    }
}
